home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / io / BufferedWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  2.1 KB  |  161 lines

  1. package java.io;
  2.  
  3. public class BufferedWriter extends Writer {
  4.    private Writer out;
  5.    // $FF: renamed from: cb char[]
  6.    private char[] field_0;
  7.    private int nChars;
  8.    private int nextChar;
  9.    private static int defaultCharBufferSize = 8192;
  10.    private String lineSeparator;
  11.  
  12.    public BufferedWriter(Writer var1) {
  13.       this(var1, defaultCharBufferSize);
  14.    }
  15.  
  16.    public BufferedWriter(Writer var1, int var2) {
  17.       super(var1);
  18.       if (var2 <= 0) {
  19.          throw new IllegalArgumentException("Buffer size <= 0");
  20.       } else {
  21.          this.out = var1;
  22.          this.field_0 = new char[var2];
  23.          this.nChars = var2;
  24.          this.nextChar = 0;
  25.          SecurityManager.enablePrivilege("UniversalPropertyRead");
  26.          this.lineSeparator = System.getProperty("line.separator");
  27.          SecurityManager.revertPrivilege();
  28.       }
  29.    }
  30.  
  31.    private void ensureOpen() throws IOException {
  32.       if (this.out == null) {
  33.          throw new IOException("Stream closed");
  34.       }
  35.    }
  36.  
  37.    void flushBuffer() throws IOException {
  38.       Object var1 = super.lock;
  39.       synchronized(var1){}
  40.  
  41.       try {
  42.          this.ensureOpen();
  43.          if (this.nextChar != 0) {
  44.             this.out.write(this.field_0, 0, this.nextChar);
  45.             this.nextChar = 0;
  46.             return;
  47.          }
  48.       } catch (Throwable var4) {
  49.          throw var4;
  50.       }
  51.  
  52.    }
  53.  
  54.    public void write(int var1) throws IOException {
  55.       Object var2 = super.lock;
  56.       synchronized(var2){}
  57.  
  58.       try {
  59.          this.ensureOpen();
  60.          if (this.nextChar >= this.nChars) {
  61.             this.flushBuffer();
  62.          }
  63.  
  64.          this.field_0[this.nextChar++] = (char)var1;
  65.       } catch (Throwable var4) {
  66.          throw var4;
  67.       }
  68.  
  69.    }
  70.  
  71.    public void write(char[] var1, int var2, int var3) throws IOException {
  72.       Object var4 = super.lock;
  73.       synchronized(var4){}
  74.  
  75.       try {
  76.          this.ensureOpen();
  77.          if (var3 < this.nChars) {
  78.             int var6 = var2;
  79.             int var7 = var2 + var3;
  80.  
  81.             while(var6 < var7) {
  82.                int var8 = Math.min(this.nChars - this.nextChar, var7 - var6);
  83.                System.arraycopy(var1, var6, this.field_0, this.nextChar, var8);
  84.                var6 += var8;
  85.                this.nextChar += var8;
  86.                if (this.nextChar >= this.nChars) {
  87.                   this.flushBuffer();
  88.                }
  89.             }
  90.  
  91.             return;
  92.          }
  93.  
  94.          this.flushBuffer();
  95.          this.out.write(var1, var2, var3);
  96.       } catch (Throwable var10) {
  97.          throw var10;
  98.       }
  99.  
  100.    }
  101.  
  102.    public void write(String var1, int var2, int var3) throws IOException {
  103.       Object var4 = super.lock;
  104.       synchronized(var4){}
  105.  
  106.       try {
  107.          this.ensureOpen();
  108.          int var6 = var2;
  109.          int var7 = var2 + var3;
  110.  
  111.          while(var6 < var7) {
  112.             int var8 = Math.min(this.nChars - this.nextChar, var7 - var6);
  113.             var1.getChars(var6, var6 + var8, this.field_0, this.nextChar);
  114.             var6 += var8;
  115.             this.nextChar += var8;
  116.             if (this.nextChar >= this.nChars) {
  117.                this.flushBuffer();
  118.             }
  119.          }
  120.       } catch (Throwable var10) {
  121.          throw var10;
  122.       }
  123.  
  124.    }
  125.  
  126.    public void newLine() throws IOException {
  127.       ((Writer)this).write(this.lineSeparator);
  128.    }
  129.  
  130.    public void flush() throws IOException {
  131.       Object var1 = super.lock;
  132.       synchronized(var1){}
  133.  
  134.       try {
  135.          this.flushBuffer();
  136.          this.out.flush();
  137.       } catch (Throwable var3) {
  138.          throw var3;
  139.       }
  140.  
  141.    }
  142.  
  143.    public void close() throws IOException {
  144.       Object var1 = super.lock;
  145.       synchronized(var1){}
  146.  
  147.       try {
  148.          if (this.out != null) {
  149.             this.flushBuffer();
  150.             this.out.close();
  151.             this.out = null;
  152.             this.field_0 = null;
  153.             return;
  154.          }
  155.       } catch (Throwable var4) {
  156.          throw var4;
  157.       }
  158.  
  159.    }
  160. }
  161.